/*************************************************************************
	> File Name: build.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年11月28日 星期日 14时38分08秒
 ************************************************************************/

#include<iostream>
#include <string>
#include <vector>

//产品类
class Product
{
public:
	void add(std::string s)
	{
		vec.push_back(s);
	}

	void show()
	{
		for (auto s : vec)
			std::cout << s << " ";
		std::cout << std::endl;
	}

private:
	std::vector<std::string> vec;
};

//build类
class Builder
{
public:
	virtual void buildPart1() = 0;
	virtual void buildPart2() = 0;

	virtual Product getResult() = 0;
};

//build1类
class Builder1 : public Builder
{
public:
	virtual void buildPart1()
	{
		p.add("部件A");
	}

	virtual void buildPart2()
	{
		p.add("部件B");
	}

	virtual Product getResult()
	{
		return p;
	}

private:
	Product p;
};

//build2类
class Builder2 : public Builder
{
public:
	virtual void buildPart1()
	{
		p.add("部件X");
	}

	virtual void buildPart2()
	{
		p.add("部件Y");
	}

	virtual Product getResult()
	{
		return p;
	}

private:
	Product p;
};

//Director类
class Director
{
public:
	void create(Builder* b)
	{
		b->buildPart1();
		b->buildPart2();
	}
};

